package cn.com.shopec.erp.base.controller;

import java.text.DecimalFormat;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.shopec.erp.base.entity.AuditSetting;
import cn.com.shopec.erp.base.service.IAuditSettingService;
import cn.com.shopec.erp.base.vo.AuditSettingVo;
import cn.com.shopec.erp.common.constant.SZSCMConstant;
import cn.com.shopec.erp.common.page.PageFinder;
import cn.com.shopec.erp.common.page.PageQuery;
import cn.com.shopec.erp.common.utils.JsonHelper2;

@Controller
@RequestMapping("base/auditSetting")
public class AuditSettingController {
	
	private Logger log = Logger.getLogger(AuditSettingController.class);
	
	@Resource
	private IAuditSettingService auditSettingService; 
	
	
	/**
	 * @methodName：addAuditSetting
	 * @Description: 跳转审核金额设置
	 * @return 
	 * @author: gaoyaxiong
	 * @date: 2013-5-22 下午15:10:03
	 */
	@RequestMapping("addAuditSetting")
	public String addAuditSetting(){
		
		return "/base/add_audit_setting";
	}
	
	
	/**
	 * @methodName：getAjaxPageFinderAuditSetting
	 * @Description: 获取审核角色设置
	 * @param ProductVo pageQuery
	 * @return 
	 * @author: gaoyaxiong
	 * @date: 2013-5-26 下午15:10:03
	 */
	@RequestMapping("getAjaxPageFinderAuditSetting")
	@ResponseBody
	public String getAjaxPageFinderAuditSetting(AuditSettingVo asVo,PageQuery pageQuery){
		PageFinder<AuditSettingVo> asVoPageFinder = auditSettingService.getPageFinderAuditSetting(asVo,pageQuery);
		ModelMap map = new ModelMap();
		map.put("Rows", asVoPageFinder.getData());
		map.put("Total", asVoPageFinder.getRowCount());
		return JsonHelper2.toJson(map);
	}
	
	
	/**
	 * @methodName：addToAuditSetting
	 * @Description:新增审核
	 * @param AuditSettingVo
	 * @return 
	 * @author: gaoyaxiong
	 * @date: 2013-5-26 下午15:10:03
	 */
	@RequestMapping("addToAuditSetting")
	@ResponseBody
	public String addToAuditSetting(AuditSettingVo asVo) {
		if(asVo != null){
			try {
				String ss = auditSettingService.addAuditSetting(asVo);
				return ss;
			} catch (Exception e) {
				log.error("addToAuditSetting"+e.getMessage(),e);
			}
			
		}
		return SZSCMConstant.FAIL;
	}
	
	/**
	 * 跳转修改页面
	 * @param id
	 * @return
	 */
	@RequestMapping("toUpdateAuditSetting")
	public String toUpdateAuditSetting(String code,ModelMap map){
		
		AuditSetting as = auditSettingService.getAuditSettingById(code);
		map.put("auditSetting", as);
		return "/base/upade_audit_setting";
		
	}
	
	/**
	 * 修改信息
	 * @param auditSetting
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("updateAuditSetting")
	@ResponseBody
	public String updateAuditSetting(AuditSetting auditSetting) throws Exception{
		if(null != auditSetting){
			try {
				auditSettingService.updateAuditSetting(auditSetting);
				return SZSCMConstant.SUCCESS;
			} catch (Exception e) {
				log.error("updateAuditSetting"+e.getMessage(),e);
			}
		}
		return SZSCMConstant.FAIL;
	}
	
}
